package socket;

import java.io.*;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Client2 {
    private Socket scoket;
    public Client2() {
        try {
            System.out.printf("正在链接服务器。。。。");
            scoket =new Socket("172.86.0.68",8088);
            System.out.printf("链接成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public void start(){
        try {
            OutputStream out=scoket.getOutputStream();
            OutputStreamWriter osw = new OutputStreamWriter(out, StandardCharsets.UTF_8);
            BufferedWriter bw=new BufferedWriter(osw);
            PrintWriter pw=new PrintWriter(bw,true);
            Scanner scan=new Scanner(System.in);
            String s =scan.next();
            while (true){
                String line=scan.nextLine();
                if ("exit".equals(line)){
                    break;
                }
                pw.println(s);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                scoket.close();//与服务器断开链接
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    public static void main(String[] args) {
     Client2 client=new Client2();
     client.start();
    }
}
